package com.ctshk.common.utils;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Random;

/**
 * 套票 订单号 相关生成
 *
 * @author 杨林
 * @version 1.0
 * @date 2021/3/25 11:57
 */
public class SeasonOrderManager {

    public static final String CUSTOM_URI = "/app/order/airexpress/air/express/appSeasonOrder/payment";

    public static final String MTR_KEY = "20Qyq9pxqgnaX8rNVnBpVttWWav3jYo8";
    public static final String MTR_AGENT_ID = "A00036";
    public static final String MTR_AGENT_USER = "CTS3";
    public static final String MTR_AGENT_PWD = "uatcts1234";

    // 积分 收款方式
    public static Long pointsCollectionWayId=1372459145921458178L;
    public static String pointsCollectionWayName="星赏会积分";
    public static Long AREA_HK = 1349239675089903631L;
    public static Long AREA_MO = 1349239675089903631L;
    public static BigDecimal TAX_RATE=new BigDecimal("0.0015");
    //动态套票添加购物车的 key
    public static final String USER_DYNAMIC_PRODUCT_TOKEN_KEY = "user:dynamic:product:";
    /**
     * 牌照号码
     */
    public static String LICENSE_NO = "test_def";
    /**
     * 咨询电话
     */
    public static String SUPPORT_NO = "test_def";

    public static Integer AFFIRM_YES = 1; //已确认
    public static Integer AFFIRM_NO = 1; //未确认

    /**
     * 获取套票 订单销售单号
     * 规则 E+部門代碼+員工編號+年後2位+月日4位+3位隨機數字
     *
     * @return
     */
    public static String getSellOrderNumer(String depCode, String empNumer) {
        StringBuffer orderNumber = new StringBuffer();
        orderNumber.append("E");
        orderNumber.append(depCode);
        orderNumber.append(empNumer);

        LocalDateTime now = LocalDateTime.now();

        String yyMMddHHmm = DateUtil.fmt(now, "yyMMddHHmm");

        orderNumber.append(yyMMddHHmm);
        return orderNumber.toString();
    }

    /**
     * 获取订单收款单号
     * 规则 SKD+年後2位+月日4位+時分秒6位+2位隨機數字
     *
     * @return String
     */
    public static String getCollectionNumber() {
        StringBuffer collectionNumber = new StringBuffer();
        collectionNumber.append("SKD");
        String year = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yy"));
        collectionNumber.append(year);
        String month = LocalDateTime.now().format(DateTimeFormatter.ofPattern("MMdd"));
        collectionNumber.append(month);
        String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("HHmmss"));
        collectionNumber.append(time);
        Random random = new Random();
        int number = random.nextInt(90) + 10;
        collectionNumber.append(number + "");
        return collectionNumber.toString();
    }

    /**
     * 获取收据编号 门市编码 为销售的部门编码
     * 规则: 門市編號+員工編號+年後2位+月日4位+A+時分秒6位+（S）
     *
     * @return
     */
    public static String getReceiptNumer(String depCode, String empNumer) {
        StringBuffer receiptNumer = new StringBuffer();
        receiptNumer.append(depCode);
        receiptNumer.append(empNumer);
        String year = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yy"));
        receiptNumer.append(year);
        String month = LocalDateTime.now().format(DateTimeFormatter.ofPattern("MMdd"));
        receiptNumer.append(month);
        receiptNumer.append("A");
        String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("HHmmss"));
        receiptNumer.append(time);
        receiptNumer.append("(s)");
        return receiptNumer.toString();
    }

    /**
     * 获取订单退款单号
     * 规则 SKD+年後2位+月日4位+時分秒6位+2位隨機數字
     *
     * @return String
     */
    public static String getRefundNumber() {
        StringBuffer refund = new StringBuffer();
        refund.append("TKD");
        String year = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yy"));
        refund.append(year);
        String month = LocalDateTime.now().format(DateTimeFormatter.ofPattern("MMdd"));
        refund.append(month);
        String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("HHmmss"));
        refund.append(time);
        Random random = new Random();
        int number = random.nextInt(90) + 10;
        refund.append(number + "");
        return refund.toString();
    }


    /* @MethodName: 查询号码 随机 生成6位数字
     * @Description: TODO
     * @Param:
     * @Return:
     * @Author: 杨林
     * @Date:2021/3/31 16:15
     **/
    public static String getQueryNo() {
        Random random = new Random();
        int flag = random.nextInt(999999);
        if (flag < 100000) {
            flag += 100000;
        }
        return String.valueOf(flag);
    }


    /* @MethodName: 下单 应该按照 对应 先后顺序去下订单
     * @Description: TODO
     * @Param:
     * @Return:
     * @Author: 杨林
     * @Date:2021/4/20 14:29
     **/
    public static List<Integer> conversionOrder(String seasonPackageProductFlag) {
        List<Integer> flagList = new ArrayList<>();
        String[] flagArr = seasonPackageProductFlag.split(",");
        for (String s : flagArr) {
            flagList.add(Integer.valueOf(s));
        }
        flagList.sort(Comparator.naturalOrder());
        return flagList;
    }

}